﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using Tickz.Tools;
using System.IO;
using System.Threading;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
namespace Show
{
   
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private delegate void InvokeDelegate(string i);
        private delegate void dsdf();
        private Thread uiThread=null;
        private void btn_submit_Click(object sender, EventArgs e)
        {
           // Control.CheckForIllegalCrossThreadCalls = false;
            Thread.CurrentThread.Name = "main";
           // this.textBox1.Text = this.textBox1.InvokeRequired.ToString();          
            uiThread = new Thread(new ThreadStart(UpdateProgressThread));
            uiThread.Start();
            Thread workThread = new Thread(new ThreadStart(DoSomething));
            workThread.Start();
           
        }

        private void DoSomething()
        {           
           //Invoke(new InvokeDelegate(stww));
            Thread.Sleep(5000);
            //uiThread.Abort();
            //MessageBox.Show("workend");
        }

        private void UpdateProgressThread()
        {
            for (int i = 0; i < 10000; i++)
            {
                Thread.Sleep(100);
                this.Invoke(new InvokeDelegate(this.getBool), i.ToString());                
            }

        }
        private void UpdateProgress(int v)
　          {

             this.progressBar1.Value = v;

　          }

        private void getBool(string uriName)
        {
            uriName = "baidu";
            string strUri = "http://www.cominter.cn/style/info/tickzCheck.asp?domain=[name]&com=yes&".Replace("[name]",uriName);
            WebRequest request = WebRequest.Create(strUri);
            WebResponse wrs = request.GetResponse();
            Stream strm = wrs.GetResponseStream();
            StreamReader sr = new StreamReader(strm);
            String line;
            while ((line = sr.ReadLine()) != null)
            {
                listBox1.Items.Add(line);
            }
            strm.Close();
           // return "";
        }

       
        
        private void notify_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MessageBox.Show("dd");
        }

        private void notify_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
                this.WindowState = FormWindowState.Normal;
            this.Activate();
            this.notify.Visible = false;
            this.ShowInTaskbar = true;   

        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)//最小化   
            {
                this.ShowInTaskbar = false;
                this.notify.Visible = true;
            }   

        }

      
       

        private void Form1_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
        }  

       

        private void button3_Click(object sender, EventArgs e)
        {
          
            string strUri = "http://domain.webmasterhome.cn/todayDel.asp";
            WebRequest request = WebRequest.Create(strUri);
            WebResponse wrs = request.GetResponse();
            Stream strm = wrs.GetResponseStream();
            StreamReader sr = new StreamReader(strm,Encoding.GetEncoding("gb2312"));
            string strAll=sr.ReadToEnd().Replace("[", "").Replace("]", "");
            string pattinStr = "<pre.*>(.*\n)*</pre>";            

            //String line;
            //while ((line = sr.ReadLine()) != null)
            //{
            //    try
            //    {
            //        if (Convert.ToBoolean(line))
            //        {
            //            arrayList.Add(line);
            //        }
            //    }
            //    catch (Exception ex)
            //    {


            //    }

            //}
            strm.Close();
            string se=Regex.Match(strAll, pattinStr).Value;

            se = se.Replace(Regex.Match(se, "<pre.*>").Value, "").Replace("</pre>", "");
            string[] strArr= se.Split('\n');
            for (int i = 0; i < strArr.Length; i++)
            {
                listBox1.Items.Add(strArr[i]); 
            }
            MessageBox.Show(listBox1.Items.Count.ToString());
            
            
        }

       

        private void progressBar1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
          //  Tickz.Tools.EmailTools mail = new EmailTools();
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //EmailTools.StmpServer = "smtp.qq.com";
            //EmailTools.StmpUser = "630419595@qq.com";
            //EmailTools.StmpPass = "0504209260";
            //bool issuccess = EmailTools.SendEmail("630419595@qq.com", "tickwudi@qq.com", "", "注册成功", "谢谢", false);
                    
        }

        private void textBox2_KeyUp(object sender, KeyEventArgs e)
        {
            
            

        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
          
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
//            MessageBox.Show(Convert.ToInt32(e.KeyChar).ToString());
            
            TextBox txx = (TextBox)sender;
            if(!string.IsNullOrEmpty(txx.SelectedText))
            {
                txx.Text = "";
            }
            //不响应事件
            e.Handled = true;
            if (e.KeyChar >= '0' && e.KeyChar <= '9')
            {//只能输入数字
                e.Handled = false;
                if (int.Parse(txx.Text + e.KeyChar) > 120)
                {
                    e.Handled = true;
                    txx.Text = "120";
                }
            }else if(Char.IsControl(e.KeyChar))
            {//输入删除
                e.Handled = false;
            }
        }
    }
}